package com.ruoyi.system.service.zhaungxiuservice.shopService.impl;

import com.ruoyi.system.domain.supe.GroupJoint;
import com.ruoyi.system.mapper.zhuangxiumapper.shopMapper.GroupJointMapper;
import com.ruoyi.system.service.zhaungxiuservice.shopService.GroupJointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Random;

@Service
public class GroupJointServiceImpl implements GroupJointService {
    @Autowired
    private GroupJointMapper groupJointMapper;

    /**
     * 查询拼团拼接
     *
     * @param jointId 拼团拼接ID
     * @return 拼团拼接
     */
    @Override
    public GroupJoint selectGroupJointById(Integer jointId)
    {
        return groupJointMapper.selectGroupJointById(jointId);
    }

    @Override
    public List<GroupJoint> listJointById(Integer productId) {
        return groupJointMapper.listJointById(productId);
    }

    /**
     * 查询拼团拼接列表
     *
     * @param groupJoint 拼团拼接
     * @return 拼团拼接
     */
    @Override
    public List<GroupJoint> selectGroupJointList(GroupJoint groupJoint)
    {
        return groupJointMapper.selectGroupJointList(groupJoint);
    }

    /**
     * 新增拼团拼接
     *
     * @param groupJoint 拼团拼接
     * @return 结果
     */
    @Override
    public int insertGroupJoint(GroupJoint groupJoint)
    {
        Integer orderIdnumone = groupJoint.getOrderIdnumone();
        groupJoint.setOrderIdOne(orderIdnumone);

        Integer productIdnum = groupJoint.getProductIdnum();
        groupJoint.setProductId(productIdnum);

        StringBuilder stringBuilder = new StringBuilder();
        Random random = new Random();
        for (int i=0;i<8;i++){
            stringBuilder.append(random.nextInt(10));
        }
        String num =stringBuilder.toString();
        groupJoint.setJointOne(num);

        groupJoint.setModifiedTime(new Date());
        groupJoint.setDelFlag("0");
        return groupJointMapper.insertGroupJoint(groupJoint);
    }

    /**
     * 修改拼团拼接
     *
     * @param groupJoint 拼团拼接
     * @return 结果
     */
    @Override
    public int updateGroupJoint(GroupJoint groupJoint)
    {
        Integer jointIdnumtwo = groupJoint.getJointIdnumtwo();
        groupJoint.setJointId(jointIdnumtwo);
        Integer orderIdnumtwo = groupJoint.getOrderIdnumtwo();
        groupJoint.setOrderIdTwo(orderIdnumtwo);
        StringBuilder stringBuilder = new StringBuilder();
        Random random = new Random();
        for (int i=0;i<8;i++){
            stringBuilder.append(random.nextInt(10));
        }
        String num =stringBuilder.toString();
        groupJoint.setJointTwo(num);
        groupJoint.setDelFlag("2");
        return groupJointMapper.updateGroupJoint(groupJoint);
    }

    /**
     * 批量删除拼团拼接
     *
     * @param jointIds 需要删除的拼团拼接ID
     * @return 结果
     */
    @Override
    public int deleteGroupJointByIds(Integer[] jointIds)
    {
        return groupJointMapper.deleteGroupJointByIds(jointIds);
    }

    /**
     * 删除拼团拼接信息
     *
     * @param jointId 拼团拼接ID
     * @return 结果
     */
    @Override
    public int deleteGroupJointById(Integer jointId)
    {
        return groupJointMapper.deleteGroupJointById(jointId);
    }
}
